package com.daify.threadlearn.chapter01.order06;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Timer;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

/**
 * @author daify
 * @date 2019-06-11
 */
public class TaskExecutor {

    private static final int NTHREADS = 100;

    private static final Executor exec = Executors.newFixedThreadPool(NTHREADS);

    public static void main(String[] args) throws IOException {

        ServerSocket serverSocket = new ServerSocket(80);
        while (true) {
            final Socket connection = serverSocket.accept();

            Runnable runnable = new Runnable() {
                @Override
                public void run() {
                    doSame(connection);
                }
            };
            exec.execute(runnable);
        }
    }

    public static void doSame(Socket connection) {
        // doSame...
    }
}
